#include <iostream>
#include <string>
#include <stack>

using namespace std;

stack<char> st;

bool isValid(string s) 
{
    if(s.size()==0) return true;
    if(s.size()%2!=0) return false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='('||s[i]=='{'||s[i]=='[')
        {
            st.push(s[i]);
        }
        else
        {
            if(st.empty()) return false;
            char c=st.top();
            st.pop();
            if((c=='('&&s[i]==')')||(c=='{'&&s[i]=='}')||(c=='['&&s[i]==']')) continue;
            else return false;
        }
    }
    if(st.empty()) return true;
}

int main()
{
    string s;
    cin >> s;
    cout << isValid(s) << endl;
    return 0;
}